import maya.cmds as mc
import maya.mel as mel
import random as rd
import tools_Persional.LZ_Tools.LZ_Tools.OF3D_PublicClass.attributes as attributes
reload(attributes)

class SDK_menager(attributes.AttributeManage):

    def LZ_SDK_menagerUI(self):
        LZ_SDK_menagerUI='LZ_SDK_menagerUI'
        if mc.window(LZ_SDK_menagerUI,q=1,ex=1):
            mc.deleteUI(LZ_SDK_menagerUI)
        mc.window(LZ_SDK_menagerUI,t='LZ_SDK_menagerUI v02   2014/08/13')
        
        mc.columnLayout('SDK_menagerUI_main_layout',columnAttach=('both', 1), rowSpacing=10, columnWidth=460 )
        
        mc.columnLayout('ObjLoad_collayout',columnAttach=('both', 1), rowSpacing=10, columnWidth=460 )
        
        ##================================
        mc.rowLayout('ObjLoad_rowLY',numberOfColumns=2, columnWidth2=(230,220), adjustableColumn=2, columnAlign=(1, 'right'), columnAttach=[(1, 'both', 2), (2, 'both', 2)] )
        
        mc.columnLayout('OrigialLoad_collayout',columnAttach=('both', 1), rowSpacing=10, columnWidth=220 )
        
        mc.rowLayout('SDK_OrigDriver_rowLY',numberOfColumns=2, columnWidth2=(80,120), adjustableColumn=2, columnAlign=(1, 'right'), columnAttach=[(1, 'both', 0), (2, 'both', 0) ] )
        mc.button(l=' Orig Driver',c=lambda *args:self.SDK_loadOrigDriver())
        mc.textField('ObjOrigDriver',ed=False)
        
        mc.setParent('OrigialLoad_collayout')
        
        #mc.text(' Origial SDK drivens-->>')
        mc.button('Origial SDK Origial',c=lambda *args:self.SDK_loadOrigObj2List())
        #----------
        mc.setParent('ObjLoad_rowLY')
        mc.columnLayout('TargetLoad_collayout',columnAttach=('both', 1), rowSpacing=10, columnWidth=220 )
        
        mc.rowLayout('SDK_TargetDriver_rowLY',numberOfColumns=2, columnWidth2=(80,120), adjustableColumn=2, columnAlign=(1, 'right'), columnAttach=[(1, 'both', 0), (2, 'both', 0) ] )
        mc.button(l='Target  Driver',c=lambda *args:self.SDK_loadTargetDriver())
        mc.textField('ObjTargetDriver',ed=False)
        
        mc.setParent('TargetLoad_collayout')
        #mc.text(' Aim SDK drivers-->>')

        mc.button('Origial SDK Target',w=50,c=lambda *args:self.SDK_loadTargetObj2List())
        
        mc.setParent('SDK_menagerUI_main_layout')
        mc.rowLayout('blendList_rowLY',numberOfColumns=2, columnWidth2=(225, 225), adjustableColumn=2, columnAlign=(1, 'right'), columnAttach=[(1, 'both', 0), (2, 'both', 0)] )
        ##====================================
        #-------------------------------------
        
        mc.columnLayout('SDK_OrigList_layout',columnAttach=('both', 1), rowSpacing=10, columnWidth=220 )
        
        
        mc.rowLayout('SDK_OrigList_rowLY',numberOfColumns=2, columnWidth2=(180,30), adjustableColumn=2, columnAlign=(1, 'right'), columnAttach=[(1, 'both', 0), (2, 'both', 0) ] )
        
        
        
        
        mc.textScrollList('SDK_OrigList',allowMultiSelection=True, height =  155,width = 180,dcc=lambda *args:self.SDK_selectOrigListObj(),sc=lambda *args:self.SDK_selectOrigIofo())
        
        
        mc.columnLayout('SDK_Origbuttons_layout',columnAttach=('both', 1), rowSpacing=10, columnWidth=30 )
        mc.button('SDK_OigUP',l='^',c=lambda *args:self.SDK_Up('SDK_OrigList'))
        mc.button('SDK_OigDN',l='v')
        
        ##-----
        mc.setParent('blendList_rowLY')
        mc.columnLayout('SDK_aimList_layout',columnAttach=('both', 1), rowSpacing=10, columnWidth=220 )
        
        
        
        mc.rowLayout('SDK_aimList_rowLY',numberOfColumns=2, columnWidth2=(180,30), adjustableColumn=2, columnAlign=(1, 'right'), columnAttach=[(1, 'both', 0), (2, 'both', 0) ] )
        
        
        mc.textScrollList('SDK_aimList',allowMultiSelection=True, height =  155,width = 180,dcc=lambda *args:self.SDK_selectTargetListObj(),sc=lambda *args:self.SDK_selectTargetIofo())
       
        
        mc.columnLayout('SDK_Aimbuttons_layout',columnAttach=('both', 1), rowSpacing=10, columnWidth=30 )
        mc.button('SDK_AimUP',l='^',c=lambda *args:self.SDK_Up('SDK_aimList'))
        mc.button('SDK_OigDN',l='v')
        
        
        ####=========================================================
        mc.setParent('SDK_menagerUI_main_layout')
        
        mc.columnLayout('SDK_mirrorButton_layout',columnAttach=('both', 1), rowSpacing=10, columnWidth=455 )
        
        mc.rowLayout('SDK_mirrorTransAxis_rowLY',numberOfColumns=4, columnWidth4=(80,140,40,140), adjustableColumn=4, columnAlign=(1, 'right'), columnAttach=[(1, 'both', 0), (2, 'both', 0), (3, 'both', 0) , (4, 'both', 0) ] )
        
        mc.text('SDK_mirrirTransAxisTest',l=' Axis Match : ')
        mc.columnLayout('SDK_OrigAxis_layout',columnAttach=('both', 1), rowSpacing=10, columnWidth=140 )
        
        mc.optionMenu('transX_Menu',label='',w=120,h=20,cc=lambda *args:self.checkTransX_Menu())

        mc.menuItem( label='X ' )
        mc.menuItem( label='Y' )
        mc.menuItem( label='Z' )
        mc.menuItem( label='-X' )
        mc.menuItem( label='-Y' )
        mc.menuItem( label='-Z' )
        
        mc.optionMenu('transX_Menu',e=True,select=1,en=False)
        
        mc.optionMenu('transY_Menu',label='',w=120,h=20,cc=lambda *args:self.checkTransY_Menu())

        mc.menuItem( label='X' )
        mc.menuItem( label='Y' )
        mc.menuItem( label='Z' )
        mc.menuItem( label='-X' )
        mc.menuItem( label='-Y' )
        mc.menuItem( label='-Z' )
        mc.optionMenu('transY_Menu',e=True,select=2,en=False)
        
        
        mc.optionMenu('transZ_Menu',label='',w=120,h=20,cc=lambda *args:self.checkTransZ_Menu())

        mc.menuItem( label='X' )
        mc.menuItem( label='Y' )
        mc.menuItem( label='Z' )
        mc.menuItem( label='-X' )
        mc.menuItem( label='-Y' )
        mc.menuItem( label='-Z' )
        mc.optionMenu('transZ_Menu',e=True,select=3,en=False)
        
        
        mc.setParent('SDK_mirrorTransAxis_rowLY')
        mc.columnLayout('SDK_TextAxis_layout',columnAttach=('both', 1), rowSpacing=10, columnWidth=40 )
        
        mc.text('01>>>',l='>>>')
        mc.text('02>>>',l='>>>')
        mc.text('03>>>',l='>>>')
        
        mc.setParent('SDK_mirrorTransAxis_rowLY')
        mc.columnLayout('SDK_TargetAxis_layout',columnAttach=('both', 1), rowSpacing=10, columnWidth=140 )
        
        mc.optionMenu('TargetTransX_Menu',label='',w=120,h=20,cc=lambda *args:self.checkTargetTransX_Menu())

        mc.menuItem( label='X' )
        mc.menuItem( label='Y' )
        mc.menuItem( label='Z' )
        mc.menuItem( label='-X' )
        mc.menuItem( label='-Y' )
        mc.menuItem( label='-Z' )
        
        mc.optionMenu('TargetTransX_Menu',e=True,select=1)
        
        mc.optionMenu('TargetTransY_Menu',label='',w=120,h=20,cc=lambda *args:self.checkTargetTransY_Menu())

        mc.menuItem( label='X' )
        mc.menuItem( label='Y' )
        mc.menuItem( label='Z' )
        mc.menuItem( label='-X' )
        mc.menuItem( label='-Y' )
        mc.menuItem( label='-Z' )
        mc.optionMenu('TargetTransY_Menu',e=True,select=2)
        
        mc.optionMenu('TargetTransZ_Menu',label='',w=120,h=20,cc=lambda *args:self.checkTargetTransZ_Menu())

        mc.menuItem( label='X' )
        mc.menuItem( label='Y' )
        mc.menuItem( label='Z' )
        mc.menuItem( label='-X' )
        mc.menuItem( label='-Y' )
        mc.menuItem( label='-Z' )
        mc.optionMenu('TargetTransZ_Menu',e=True,select=3)
        


        
        mc.setParent('SDK_mirrorButton_layout')
        mc.button('mirror SDK',c=lambda *args:self.SDK_setDrivenKeyForList())
        mc.button('mirror_Blendd_SDK',c=lambda *args:self.blendshapeMirrorSDK())
        
        
        mc.setParent('SDK_menagerUI_main_layout')
        mc.columnLayout('currentBlendWeightList_layout',columnAttach=('both', 1), rowSpacing=10, columnWidth=455 )
        mc.scrollField('currentSDK_info_SF',w=400,h=100,ed=False,enterCommand=lambda *args:self.selectAniCurveNode())#,ed=False
        
        
        mc.window(LZ_SDK_menagerUI,e=True,widthHeight=(460, 510))
        
        
        
        mc.setParent( '..' )

        #############child3 start########

        #mc.tabLayout( tabs, edit=True, tabLabel=((child1, 'Copy Driven Keys'), (child2, 'Mirror Driven Keys'),(child3 , 'sdk')) )
        mc.showWindow(LZ_SDK_menagerUI)
    
    ####====================================================================================
    ###------------------------------------------------------------------------------------
    #-------------------------------------------------------------------------------
    def checkTransX_Menu(self):
    
        selectOp=[1,2,3,4,5,6]
        selOpTX=mc.optionMenu('transX_Menu',q=True,select=True)
        selOpTY=mc.optionMenu('transY_Menu',q=True,select=True)
        selOpTZ=mc.optionMenu('transZ_Menu',q=True,select=True)
        
        
        if selOpTX==selOpTY:
            selectOp.remove(selOpTX)
            if selOpTZ in selectOp:
                selectOp.remove(selOpTZ)

            mc.optionMenu('transY_Menu',e=True,select=rd.choice(selectOp))
        selectOp=[1,2,3,4,5,6] 
        if selOpTX==selOpTZ:
            selectOp.remove(selOpTX)
            if selOpTY in selectOp:
                selectOp.remove(selOpTY)

            mc.optionMenu('transZ_Menu',e=True,select=rd.choice(selectOp))
    def checkTransY_Menu(self):
    
        selectOp=[1,2,3,4,5,6]
        selOpTX=mc.optionMenu('transX_Menu',q=True,select=True)
        selOpTY=mc.optionMenu('transY_Menu',q=True,select=True)
        selOpTZ=mc.optionMenu('transZ_Menu',q=True,select=True)
        
        
        if selOpTY==selOpTX:
            selectOp.remove(selOpTY)
            if selOpTZ in selectOp:
                selectOp.remove(selOpTZ)

            mc.optionMenu('transX_Menu',e=True,select=rd.choice(selectOp))
        selectOp=[1,2,3,4,5,6]    
        if selOpTY==selOpTZ:
            selectOp.remove(selOpTY)
            if selOpTX in selectOp:
                selectOp.remove(selOpTX)

            mc.optionMenu('transZ_Menu',e=True,select=rd.choice(selectOp))
    def checkTransZ_Menu(self):
    
        selectOp=[1,2,3,4,5,6]
        selOpTX=mc.optionMenu('transX_Menu',q=True,select=True)
        selOpTY=mc.optionMenu('transY_Menu',q=True,select=True)
        selOpTZ=mc.optionMenu('transZ_Menu',q=True,select=True)
        
        
        if selOpTZ==selOpTX:
            selectOp.remove(selOpTZ)
            if selOpTY in selectOp:
                selectOp.remove(selOpTY)

            mc.optionMenu('transX_Menu',e=True,select=rd.choice(selectOp))
        selectOp=[1,2,3,4,5,6]    
        if selOpTZ==selOpTY:
            selectOp.remove(selOpTZ)
            if selOpTX in selectOp:
                selectOp.remove(selOpTX)

            mc.optionMenu('transY_Menu',e=True,select=rd.choice(selectOp))
    ##############################################################################      
    def checkTargetTransX_Menu(self):
    
        selectOp=[1,2,3,4,5,6]
        selOpTX=mc.optionMenu('TargetTransX_Menu',q=True,select=True)
        selOpTY=mc.optionMenu('TargetTransY_Menu',q=True,select=True)
        selOpTZ=mc.optionMenu('TargetTransZ_Menu',q=True,select=True)
        
        
        if selOpTX==selOpTY:
            selectOp.remove(selOpTX)
            if selOpTZ in selectOp:
                selectOp.remove(selOpTZ)

            mc.optionMenu('TargetTransY_Menu',e=True,select=rd.choice(selectOp))
        selectOp=[1,2,3,4,5,6] 
        if selOpTX==selOpTZ:
            selectOp.remove(selOpTX)
            if selOpTY in selectOp:
                selectOp.remove(selOpTY)

            mc.optionMenu('TargetTransZ_Menu',e=True,select=rd.choice(selectOp))
    def checkTargetTransY_Menu(self):
    
        selectOp=[1,2,3,4,5,6]
        selOpTX=mc.optionMenu('TargetTransX_Menu',q=True,select=True)
        selOpTY=mc.optionMenu('TargetTransY_Menu',q=True,select=True)
        selOpTZ=mc.optionMenu('TargetTransZ_Menu',q=True,select=True)
        
        
        if selOpTY==selOpTX:
            selectOp.remove(selOpTY)
            if selOpTZ in selectOp:
                selectOp.remove(selOpTZ)

            mc.optionMenu('TargetTransX_Menu',e=True,select=rd.choice(selectOp))
        selectOp=[1,2,3,4,5,6]    
        if selOpTY==selOpTZ:
            selectOp.remove(selOpTY)
            if selOpTX in selectOp:
                selectOp.remove(selOpTX)

            mc.optionMenu('TargetTransZ_Menu',e=True,select=rd.choice(selectOp))
    def checkTargetTransZ_Menu(self):
    
        selectOp=[1,2,3,4,5,6]
        selOpTX=mc.optionMenu('TargetTransX_Menu',q=True,select=True)
        selOpTY=mc.optionMenu('TargetTransY_Menu',q=True,select=True)
        selOpTZ=mc.optionMenu('TargetTransZ_Menu',q=True,select=True)
        
        
        if selOpTZ==selOpTX:
            selectOp.remove(selOpTZ)
            if selOpTY in selectOp:
                selectOp.remove(selOpTY)

            mc.optionMenu('TargetTransX_Menu',e=True,select=rd.choice(selectOp))
        selectOp=[1,2,3,4,5,6]    
        if selOpTZ==selOpTY:
            selectOp.remove(selOpTZ)
            if selOpTX in selectOp:
                selectOp.remove(selOpTX)

            mc.optionMenu('TargetTransY_Menu',e=True,select=rd.choice(selectOp))
    
    
    #-------------------------------------------------------------------------------
    ###-------------------------------------------------------------------------------------
    def SDK_selectOrigListObj(self):
        selectObj=mc.textScrollList('SDK_OrigList',q=True, si=True)
        mc.select(selectObj)
    def SDK_selectTargetListObj(self):
        selectObj=mc.textScrollList('SDK_aimList',q=True, si=True)
        mc.select(selectObj)
        
    def SDK_loadOrigDriver(self):
        driver=self.getSelectedAttr()
        mc.textField('ObjOrigDriver',e=True,text=driver)
    def SDK_loadTargetDriver(self):
        driver=self.getSelectedAttr()
        mc.textField('ObjTargetDriver',e=True,text=driver)
        
    def SDK_loadOrigObj2List(self):
        objsel=mc.ls(sl=True)
        
        mc.textScrollList('SDK_OrigList',e=True, ra =True)
        mc.textScrollList('SDK_OrigList',e=True, a =objsel)
    def SDK_loadTargetObj2List(self):
        objsel=mc.ls(sl=True)
        
        mc.textScrollList('SDK_aimList',e=True, ra =True)
        mc.textScrollList('SDK_aimList',e=True, a =objsel)
    def SDK_Up(self,textSList):
        currentselectI=mc.textScrollList(textSList,q=True,sii=True)
        currentselect=mc.textScrollList(textSList,q=True,si=True)

        for num in range(len(currentselectI)):
            
            if currentselectI[num]==1:
                pass
            else:

                if num>0:
                    mc.textScrollList(textSList,e=True,sii=currentselectI[num-1])
                    selectItem=mc.textScrollList(textSList,q=True,si=True)

                    if (currentselect[num-1])==selectItem:

                        pass
                    else:

                        mc.textScrollList(textSList,e=True,ri=currentselect[num])
                        mc.textScrollList(textSList,e=True,appendPosition=[currentselectI[num]-1,currentselect[num]])
                else:
                    mc.textScrollList(textSList,e=True,ri=currentselect[num])
                    mc.textScrollList(textSList,e=True,appendPosition=[currentselectI[num]-1,currentselect[num]])
                    
    
    ##--------------------------------------------------------------------------------------------
    def SDK_setDrivenKeyForList(self,mirrorAxis='X'):
    
        
        animaCurves=[]
        
        
        origDriver=mc.textField('ObjOrigDriver',q=True,text=True)
        targetDriver=mc.textField('ObjTargetDriver',q=True,text=True)

        AllOrigDrivens=mc.textScrollList('SDK_OrigList',q=True, ai=True)
        AllTargetDrivens=mc.textScrollList('SDK_aimList',q=True, ai=True)
        
        for num in range(len(AllOrigDrivens)):
            origDriven=AllOrigDrivens[num]
            OrigsetDrivenInfo=self.getSDKconnectionInfo(origDriver,origDriven)
            
            targetDriven=AllTargetDrivens[num]

            TargetSetDrivenInfo=self.getSDKconnectionInfo(targetDriver,targetDriven)
            
            OrigSDKAttr=[]
            targetSDKAttr=[]
            
            for sdinfo in OrigsetDrivenInfo:
                OrigSDKAttr.append(sdinfo[2])
                animaCurves.append(sdinfo[1])
                
                targetDrivenAttr=str(sdinfo[2]).replace(AllOrigDrivens[num],AllTargetDrivens[num])
                targetSDKAttr.append(targetDrivenAttr)
                
            for sdinfo in OrigsetDrivenInfo:
                
                origfloatValue=self.LZ_getSDKFloat(sdinfo[1])
                origvalue=self.LZ_getSDKValue(sdinfo[1])
                
                targetDrivenAttr=str(sdinfo[2]).replace(AllOrigDrivens[num],AllTargetDrivens[num])
                IfExistAniNode=0
                
                
                currentSdkAttr=[]
                '''
                setDrivenKeyframe for the driven objects which have no any animateUL node input 
                so ,we can change the value base on the argument get from original driven objects 
                vvvvv
                '''
                if TargetSetDrivenInfo==[]:
                    self.setDrivenKey(targetDriver,targetDrivenAttr,1000,0)
                else:
                    
                    for tsdinfo in TargetSetDrivenInfo:
                        
                        currentSdkAttr.append(tsdinfo[2])

                    if targetDrivenAttr in currentSdkAttr:
                        pass

                    else:

                        IfExistAniNode=1

                    if IfExistAniNode==1:
                        self.setDrivenKey(targetDriver,targetDrivenAttr,1000,0)

                
            #self.SDK_getValueFromeOrig(origDriver,AllOrigDrivens[num],targetDriver,AllTargetDrivens[num])
            
            targetTransX=mc.optionMenu('TargetTransX_Menu',q=True,v=True)
            targetTransY=mc.optionMenu('TargetTransY_Menu',q=True,v=True)
            targetTransZ=mc.optionMenu('TargetTransZ_Menu',q=True,v=True)
            
            self.SDK_getValueFromeOrig(origDriver,AllOrigDrivens[num],targetDriver,AllTargetDrivens[num],AxisX=targetTransX,AxisY=targetTransY,AxisZ=targetTransZ)
            '''
            
            
            '''

        return(animaCurves)
        

    def blendshapeMirrorSDK(self,OrigPrex='L_',targetPrex='R_'):
        AllOrigDrivens=mc.textScrollList('SDK_OrigList',q=True, ai=True)
        AllTargetDrivens=mc.textScrollList('SDK_aimList',q=True, ai=True)
        
        if len(AllOrigDrivens) ==len(AllTargetDrivens):
            for numnode in range(len(AllOrigDrivens)):
                if mc.nodeType(AllOrigDrivens[numnode])=='blendShape' and mc.nodeType(AllTargetDrivens[numnode])=='blendShape':
                    blendWeightName=self.SDK_getWeightName(AllOrigDrivens[numnode])
                    for bwn in blendWeightName:
                        if OrigPrex in bwn:
                            origAttr=str(AllOrigDrivens[numnode])+'.'+str(bwn)
                            
                            targetAttr=str(AllTargetDrivens[numnode])+'.'+str(bwn).replace(OrigPrex,targetPrex)
                            Origdrivers=self.SDK_getDriver(origAttr)
                            for ogdr in Origdrivers:
                                targetDriver=str(ogdr).replace(OrigPrex,targetPrex)
                            
                                self.SDK_blendshapeMirror(ogdr,origAttr,targetDriver,targetAttr)
    def SDK_blendshapeMirror(self,origdriver,origAttr,targetdriver,targetAttr):
        origDrivenobj=origAttr.split('.')[0]
        origDrivenAttr=origAttr.split('.')[1]
        infoSDK=self.getSDKconnectionInfo(origdriver,origDrivenobj)
        
        targetDrivenobj=targetAttr.split('.')[0]
        targetDrivenAttr=targetAttr.split('.')[1]
        
        anicurve=''
        for info in infoSDK:
            if origDrivenAttr in info[2]:
                anicurve=info[1]
            if anicurve!='':
                floatValue=self.LZ_getSDKFloat(anicurve)
                value=self.LZ_getSDKValue(anicurve)
                
                if 'No drivers.' in self.SDK_getDriver(targetAttr)[0] :
                    self.setDrivenKey(targetdriver,targetAttr,1000,1)
                else:
                
                    
                    infoTargetSDK=self.getSDKconnectionInfo(targetdriver,targetDrivenobj)
                    for ifTg in infoTargetSDK:
                        if targetDrivenAttr in ifTg[2]:
                            mc.delete(ifTg[1])
                    self.setDrivenKey(targetdriver,targetAttr,1000,1)
                CurrentinfoTargetSDK=self.getSDKconnectionInfo(targetdriver,targetDrivenobj)
                
                currentTargetAnicurve=''
                for cinfotg in CurrentinfoTargetSDK:
                    if targetDrivenAttr in cinfotg[2]:
                        currentTargetAnicurve=cinfotg[1]
                print(currentTargetAnicurve,floatValue)
                for vlnum in range(len(floatValue)):
                    if currentTargetAnicurve!='':
                        self.LZ_setKeyframe(currentTargetAnicurve,floatValue[vlnum],value[vlnum])
                    
                    if 1000 in floatValue:
                        pass
                    else:
                    
                        self.SDK_cutKey(currentTargetAnicurve,(1000,1000))
                    
    
    def SDK_getValueFromeOrig(self,OrigDriver,OrigDriven,targetDriver,targetDriven,AxisX='X',AxisY='Y',AxisZ='Z'):
        OrigInfo=self.getSDKconnectionInfo(OrigDriver,OrigDriven)
        targetInfo=self.getSDKconnectionInfo(targetDriver,targetDriven)
        
        #axisSDKMatch=self.SDK_checkValueAxis()
        AxisNeedAttr=['translate','rotate','scale']
        
        '''
        rebuild the group of OrigInfo 
        
        '''
        AxisMatchX=AxisX.split('-')[-1]
        AxisMatchY=AxisY.split('-')[-1]
        AxisMatchZ=AxisZ.split('-')[-1]
        
        if len(AxisX.split('-'))==1:
            AxisMatchXPN='positive'
        elif len(AxisX.split('-'))==2:
            AxisMatchXPN='negetive'
            
        if len(AxisY.split('-'))==1:
            AxisMatchYPN='positive'
        elif len(AxisY.split('-'))==2:
            AxisMatchYPN='negetive'
            
        if len(AxisZ.split('-'))==1:
            AxisMatchZPN='positive'
        elif len(AxisZ.split('-'))==2:
            AxisMatchZPN='negetive'
            
        
        OrigInfoMatch=[]
        
        for OGIF in OrigInfo:
            
            if ('translate' in OGIF[2]) or ('scale' in OGIF[2] ) or ('rotate' in OGIF[2]):
                if ('X' in OGIF[2]) :
                    AxisMtchOGIF=OGIF[2].replace('X',AxisMatchX)
                    AxisMatchPN=AxisMatchXPN
                if ('Y' in OGIF[2]) :
                    AxisMtchOGIF=OGIF[2].replace('Y',AxisMatchY)
                    AxisMatchPN=AxisMatchYPN
                if ('Z' in OGIF[2]) :
                    AxisMtchOGIF=OGIF[2].replace('Z',AxisMatchZ)
                    AxisMatchPN=AxisMatchZPN
                            
                OrigInfoMatch.append([OGIF[0],OGIF[1],AxisMtchOGIF,AxisMatchPN,OGIF[2]])
                #
            else:
                OrigInfoMatch.append([OGIF[0],OGIF[1],OGIF[2],'positive',OGIF[2]])
            
            
        
        '''
        find the animation node matched
        
        '''
        animaULMatch=[]

        for OGIFMatch in OrigInfoMatch:
            for tgIF  in targetInfo:
                
                if tgIF[2].split('.')[-1] == OGIFMatch[2].split('.')[-1]:
                    animaULMatch.append([OGIFMatch[1],tgIF[1],OGIFMatch[3],OGIFMatch[4]])
                else:
                    pass

        
        '''
        
        '''
        for anMatch in animaULMatch:
            PNValue=1
            print(anMatch)
            if ('translate' in anMatch[3]) or ('scale' in anMatch[3]):
                if anMatch[2]=='positive':
                    PNValue=1
                elif anMatch[2]=='negetive':
                    PNValue=-1
            elif 'rotate' in anMatch[3]:
                if anMatch[2]=='positive':
                    PNValue=-1
                elif anMatch[2]=='negetive':
                    PNValue=1

            origfloatValue=self.LZ_getSDKFloat(anMatch[0])
            origValue=self.LZ_getSDKValue(anMatch[0])

            for oflvNM in range(len(origfloatValue)):

                self.LZ_setKeyframe(anMatch[1],origfloatValue[oflvNM],origValue[oflvNM]*PNValue)
            
            if 1000 in anMatch:
                pass
            else:
    
                self.SDK_cutKey(anMatch[1],(1000,1000))
                                
    def SDK_checkValueAxis(self):
        transX=mc.optionMenu('transX_Menu',q=True,v=True)
        transY=mc.optionMenu('transY_Menu',q=True,v=True)
        transZ=mc.optionMenu('transZ_Menu',q=True,v=True)
        
        return (transX,transY,transZ)
        
        
        
    
    def SDK_selectOrigIofo(self):
        
        infoSDKOrig=''
        
        selectObj=mc.textScrollList('SDK_OrigList',q=True, si=True)[0]
        OrigDriver=mc.textField('ObjOrigDriver',q=True,text=True)
        

        infoSDK_Orig=self.getSDKconnectionInfo(OrigDriver,selectObj)
        
        for infoorig in infoSDK_Orig:
            info= '{'+ infoorig[0]+' >>> ' +infoorig[1]+' >>> '+infoorig[2]+'}'+'\n'
            infoSDKOrig=infoSDKOrig+info

        
        mc.scrollField('currentSDK_info_SF',e=True, text=infoSDKOrig)
        #mc.textField('currentSDK_info_TF',e=True,multiline=True,wordWrap=True,bgc=[0.6,0.6,0],text=infoSDKOrig)
    def SDK_selectTargetIofo(self):
        
        infoSDKOrig=''
        
        selectObj=mc.textScrollList('SDK_aimList',q=True, si=True)[0]
        OrigDriver=mc.textField('ObjTargetDriver',q=True,text=True)
        

        infoSDK_Orig=self.getSDKconnectionInfo(OrigDriver,selectObj)
        
        for infoorig in infoSDK_Orig:
            info= '{'+ infoorig[0]+' >>> ' +infoorig[1]+' >>> '+infoorig[2]+'}'+'\n'
            infoSDKOrig=infoSDKOrig+info

        
        mc.scrollField('currentSDK_info_SF',e=True, text=infoSDKOrig)
        #mc.textField('currentSDK_info_TF',e=True,multiline=True,wordWrap=True,bgc=[0.6,0.6,0],text=infoSDKOrig)
        
    ###------------------------------------------------------------------------------------
    '''
    LZ_getSDKFloat('animCurveUL6')  get the list of all floatChange  
    '''
    def LZ_getSDKFloat(self,animaNode):
        floatChange=mc.keyframe(animaNode,q=True,floatChange=True)
        return floatChange
    '''
    LZ_getSDKValue('animCurveUL6')            get the list of all valueChange  
    '''
    def LZ_getSDKValue(self,animaNode):
        valueChange=mc.keyframe(animaNode,q=True,valueChange=True)
        return valueChange
    '''
    LZ_getSDKIndex('animCurveUL6')      get the list of all indexs
    '''
    def LZ_getSDKIndex(self,animaNode):
        index=mc.keyframe(animaNode,q=True,indexValue=True)
        return index
    '''
    LZ_setKeyframe('animCurveUL6',10,5)     set the value is 5 when the floatValue is 10
    ''' 
    def LZ_setKeyframe(self,animaNode,float,value):
        mc.setKeyframe(animaNode,f=float,v=value)
    '''
    
    ''' 
    def createNodeAnima(self,type=0,name=''):
    
        if type==0:
            nodename='animCurveUA'
        else:
            nodename='animCurveUL'
        mc.createNode(nodename,n=name)
        
    def SDK_cutKey(self,animaNode,fload=(999,1000)):
        mc.cutKey(animaNode,f=fload)

    '''
    getSDKconnectionInfo(string ,driven)                string is a XXX.attribute   driven is a object name
    
    getSDKconnectionInfo('xxx.translateX' ,'sphere1')   
    '''    
    def getSDKconnectionInfo(self,driver,driven):
    
        drivers=mc.setDrivenKeyframe(driven,q=1,dr=1)
        drivenAttrs=mc.setDrivenKeyframe(driven,q=1,dn=1)
        
        AnimaCurve=[]
        driverAnimaCurve=[]
        driverCurves=[]
        
        SDKconnectionInfoAll=[]
        
        if driver in drivers:
            driverChilddren=mc.listConnections(driver,d=True)
            
            for dcr in driverChilddren:
                if mc.nodeType(dcr)=='unitConversion':
                    anicurve=mc.listConnections(str(dcr)+'.output',d=True)[0]
                    driverCurves.append(anicurve)
                elif 'animCurve' in mc.nodeType(dcr):
                    driverCurves.append(dcr)
                    
        
        for aa in drivenAttrs:
            sourceConnection=mc.listConnections(str(driven),s=True)
            
            if sourceConnection !=None:
                for sc in sourceConnection:
                
                    if 'animCurve' in mc.nodeType(sc):
                        if  sc not in AnimaCurve:
                            AnimaCurve.append(sc)
                    elif mc.nodeType(sc)=='blendWeighted':
                        curves=mc.listConnections(str(sc)+'.input',s=True)
                        for cvs in curves:
                            if  cvs not in AnimaCurve:
                                AnimaCurve.append(cvs)
                    elif mc.nodeType(sc)=='unitConversion':
                        uniInput=mc.listConnections(str(sc)+'.input',s=True)[0]
                        if mc.nodeType(uniInput)=='blendWeighted':
                            bwinput=mc.listConnections(str(uniInput)+'.input',s=True)
                            for bwi in bwinput:
                                if 'animCurve' in mc.nodeType(bwi):
                                    if  bwi not in AnimaCurve:
                                        AnimaCurve.append(bwi)
                                if mc.nodeType(bwi)=='unitConversion':
                                    bwiuniInput=mc.listConnections(str(bwi)+'.input',s=True)[0]
                                    if 'animCurve' in mc.nodeType(bwiuniInput):
                                        if  bwiuniInput not in AnimaCurve:
                                            AnimaCurve.append(bwiuniInput)
                            
        
        for ac in AnimaCurve:
            if ac in driverCurves:
                driverAnimaCurve.append(ac)
        for dac in driverAnimaCurve:
            destinationAttr='none'
            destination=mc.listConnections(str(dac)+'.output',d=True)[0]
            if mc.nodeType(destination)=='blendWeighted':
                destinationAttr=mc.listConnections(str(destination)+'.output',d=True,p=True)[0]
            elif mc.nodeType(destination)=='transform' or mc.nodeType(destination)=='blendShape':
                
                destinationAttr=mc.listConnections(str(dac)+'.output',d=True,p=True)[0]
            
            else:
                inputAttr=mc.listConnections(str(dac)+'.output',d=True,p=True)[0]
                
                inputObj=str(inputAttr).split('.')[0]
                
                if mc.nodeType(inputObj)=='unitConversion':
                    inoutBlendweight=mc.listConnections(str(inputObj)+'.output',d=True)[0]
                    Blendweightout=mc.listConnections(str(inoutBlendweight)+'.output',d=True)[0]
                    destinationAttr=mc.listConnections(str(Blendweightout)+'.output',d=True,p=True)[0]
                elif mc.nodeType(inputObj)=='blendWeighted':
                    destinationAttr=mc.listConnections(str(destination)+'.output',d=True,p=True)[0]
            
                
            SDKconnectionInfo=[driver,dac,destinationAttr]
            
            SDKconnectionInfoAll.append(SDKconnectionInfo)
        return SDKconnectionInfoAll

    '''
    def getSelectedAttr(self):
        "get Selected attribute name form mainChannelBox"
        mel.eval('string $attrName = "";')
        mc.channelBox("mainChannelBox",e=True,exe=['$attrName = "#P.#A";',1])
        res = mel.eval("string $res = $attrName")
        return res

    ''' 
    ##===========================================================================
    '''
    self.setDrivenKey('xxx.translateX','bbb.translateY',driverV=0,drivenV=0)
    '''
    def setDrivenKey(self,driverAttr,drivenAttr,driverV,drivenV):

        mc.setDrivenKeyframe(drivenAttr, cd=driverAttr,dv=driverV,v=drivenV)   
    '''


    '''
    def SDK_getDriver(self,attr):
        drivers=mc.setDrivenKeyframe(attr,q=True,dr=True)
        return drivers
        
    def SDK_getWeightName(self,blendShapeNode):
        aliases=mc.aliasAttr(blendShapeNode,q=True)
        blendshapeTarget=[]
        for bt in range(len(aliases)/2):
            blendshapeTarget.append(aliases[bt*2])
        return(blendshapeTarget)
    def selectAniCurveNode(self):
        texstSelect=mc.scrollField('currentSDK_info_SF',q=True,selection=True)
        mc.select(texstSelect)
